

<?php require_once '../config/config.php'; ?>
<?php

class DB {

    public $connection; //Thuộc tính

    public function getConnection() {//Phương thức
        $this->connection = mysql_connect(host . ":" . post, user, password) or die(mysql_error());
        mysql_select_db(db, $this->connection);
        return $this->connection;
    }

    public function query($query) {
        mysql_query('SET NAMES utf8', $this->connection);
        $data = mysql_query($query, $this->connection);
        $rows = array();
        while ($row = mysql_fetch_assoc($data)) {
            $rows[] = $row;
        }
        return $rows;
    }

    public function works($query = NULL) {
        if ($query) {
            mysql_query('SET NAMES utf8', $this->connection);
            $data = mysql_query($query, $this->connection);
            $rows = array();
            while ($row = mysql_fetch_assoc($data)) {
                $rows[] = $row;
            }
            return $rows;
        } else {
            $this->getConnection();
            $query = "SELECT * FROM works LIMIT 0,10 ";
            $works = $this->query($query);
            return $works;
        }
    }

}
?>



